package nowcoder;

import java.io.*;
import java.util.*;

public class B_68 {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
    static int T;
    static int cin() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static void _solve() throws IOException {
        int n = cin(), a = cin(), b = cin();
        int res = 0x3f3f3f3f;
        for (int i = 0; i < n; i ++ ) {
            int k = cin(), x = cin(), y = cin();
            while (k -- > 0) {
                int price = cin();
                if (price >= x && price >= a) {
                    price = price - y - b;
                } else if (price >= x) {
                    price -= y;
                } else if (price >= a) {
                    price -= b;
                }
                res = Math.min(res, price);
            }
        }
        if (res < 0) res = 0;
        out.println(res);
    }

    public static void main(String[] args) throws IOException {
        T = cin();
        while ( T -- > 0) {
            _solve();
        }
        out.flush();
    }
}